/**
* @Title: orgGrading_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEQI001
* @date 2014年10月29日 下午4:48:14
* @version V1.0
*/
;
(function(){
	'use strict';
	var app = angular.module('fwa.mainApp');
	app.controller('DrugstoreRuleCtrl', ['$scope','$http','$modal','BaseURL','Modal',
		                                function($scope,$http,$modal,baseUrl,Modal){
		
		
		  initDrugstoreRuleInfo();
			
			
			/**
			 * 初始化药店考评规则信息
			 */
			function initDrugstoreRuleInfo(){
				$scope.loading = true;
				var parameter={
						categoryType:'02' //药店考评规则
				             };
				 $http({
						method : 'post',
						cache : false,
						url : baseUrl + 'evaluationRule/loadEvaluationRules.do',
						params :parameter
					}).success(function(response, status, headers, config) {
						 $scope.loading =false;
						 if(response){
							    var flag=response.flag;
								var list=response.list;
								 if(flag){
									  $scope.dataList=list;
								 }else{
									 Modal.alert("加载定点药店考评规则数据失败!");
								 }
						 }
						
					});
				
				
				
			}
			
			
			/**
			 * 新增规则
			 */
			$scope.addRule=function(){
			$scope.categoryType="2"; //药店
		    var scope = $scope.$new();
			var modalInstance = $modal.open({
			      templateUrl: baseUrl+'views/hcpms/evaluation/evaluationRule/addDrugStoreRule_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:'AddDrugStoreRuleCtrl'
			      });
				
			}
			
			/**
			 * 编辑规则
			 */
			$scope.editorRule=function(id){
				$scope.categoryType="2"; //医院
				$scope.id=id; //药店id
			    var scope = $scope.$new();
				var modalInstance = $modal.open({
				      templateUrl: baseUrl+'views/hcpms/evaluation/evaluationRule/editorDrugStoreRule_view.html',
				      backdrop:'static',
					  size:'sm',
					  scope:scope,
					  controller:'EditorDrugStoreRuleCtrl'
				      });
		
	               }
			
			
			
			/**
			 * 刷新当前页面的请求
			 */
			$scope.flashStoryCurrentPage=function(){
				initDrugstoreRuleInfo();
			}
			
			
			/**
			 * 新增扣分设置
			 */
			$scope.addMarkScoreSet=function(scoreList,markRuleId){
				$scope.categoryType="2"; //药店
			    var scope = $scope.$new();
			        scope.scoreList=scoreList;
			        scope.markRuleId=markRuleId;
				var modalInstance = $modal.open({
				      templateUrl: baseUrl+'views/hcpms/evaluation/evaluationRule/addMarkScoreDialog.html',
				      backdrop:'static',
					  size:'sm',
					  scope:scope,
					  controller:'AddMarkScoreDialogCtr'
				      });
					
				}
			
			/**
			 * 删除规则
			 */
			$scope.deleteRule=function(){
				var selectCheckBoxItem=$("input[name='categoryCheck']:checked");
				var selectItemArray=new Array();
				
				if(selectCheckBoxItem.length>0){
					
					$.each(selectCheckBoxItem,function(index,item){
						var selectValueId=item.value;
						selectItemArray.push(selectValueId);
					});
					
					
					Modal.confirm('确认要删除吗？', function(){
						
						
						var parameter={
								categoryType:'02', //药店考评规则
								list:selectItemArray
						        };
						 $http({
								method : 'post',
								cache : false,
								url : baseUrl + 'evaluationRule/deleteEvaluationRules.do',
								params :parameter
							}).success(function(response, status, headers, config) {
								 if(response){
									    if(response.flag){
									    	initDrugstoreRuleInfo();
									    	Modal.alert(response.msg);
									    }else{
									    	Modal.alert(response.msg);
									    }
								 }else{
									 Modal.alert("返回数据失败!");
								 }
								
							});
						
						
						
						
					});
					
					
				}else{
					Modal.alert("请选择要删除的记录!");
				}
			}
					
		
		
		
		
		
		
		
		
}]);
	

})();